// Agent customer in project publicprintingwithjason

/* Initial beliefs and rules */

//at the start the customer wants to walk randomly
walkto(anywhere).

/* Initial goals */

//the customer wants to walk
!walk.
//and also print something eventually
!printsomething.

/* Plans */

//if the customer wants to walk to somewhere and he has not arrived there yet,
//he will keep walking until at(P) becomes true   
+!walk : walkto(P) & not at(P)
	<- 
	walkto(P);
	!!walk.

//as soon as the customer arrives at the printer pointed by the server he will
//get the job and start to walk and eventually will print again
+!walk : walkto(P) & at(P) & getprintat(P1) & P == P1
	<- 
	getprint;
	-getprintat(P);
	-+walkto(anywhere);
	!!walk;
	!!printsomething.

//if something happen while walking the customer will just start over	
-!walk : true
	<-
	.print("Something is wrong...");
	.wait(1000);
	!!walk.

//eventually the customer wants to print something
//in order to do that he will contact the server
//asking for a new print job
+!printsomething : true
	<- 
	.random(X);
	.wait(X*5000+2000);
	 
	.print("Sending something to be printed.");
	.wait(1000);
	.send(server, achieve, createjob).

//if the server is not able to create the print job
//the user will try again later	
+error[source(server)] : true 
	<-
	-error[source(server)];
	-+walkto(anywhere);
	!!printsomething.

//as soon as the server respond to the job creation,
//the customer will walk to the printer to get his print
+getprintat(P)[source(server)] : true 
	<-
	-getprintat(P)[source(server)];
	+getprintat(P);
	-+walkto(P).
				